package org.dfzt.modules.online.cgform.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dfzt.common.system.service.ISysBaseAPI;
import org.dfzt.common.util.SpringContextUtils;
import org.dfzt.modules.online.cgform.entity.OnlCgformField;
import org.jeecgframework.poi.handler.impl.ExcelDataHandlerDefaultImpl;
import org.jeecgframework.poi.util.PoiPublicUtil;


public class OnlineExcelDataHandler extends ExcelDataHandlerDefaultImpl {
    Map<String, OnlCgformField> onlCgformFieldMap;
    ISysBaseAPI iSysBaseAPI;
    String uploadPath;
    String online;
    String uploadType;

    public OnlineExcelDataHandler(List<OnlCgformField> paramList, String paramString1, String paramString2) {
        this.onlCgformFieldMap = a(paramList);
        this.uploadPath = paramString1;
        this.online = "online";
        this.uploadType = paramString2;
        this.iSysBaseAPI = (ISysBaseAPI) SpringContextUtils.getBean(ISysBaseAPI.class);
    }

    private Map<String, OnlCgformField> a(List<OnlCgformField> paramList) {
        HashMap hashMap = new HashMap();

        for (OnlCgformField onlCgformField : paramList) {
            hashMap.put(onlCgformField.getDbFieldTxt(), onlCgformField);
        }
        return hashMap;
    }


    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        String str = a(originKey);
        if (value instanceof Double) {
            map.put(str, PoiPublicUtil.doubleToString((Double) value));
        } else if (value instanceof byte[]) {
            byte[] arrayOfByte = (byte[]) value;
            String str1 = org.dfzt.modules.online.cgform.util.b.a(arrayOfByte, this.uploadPath, this.online, this.uploadType);
            if (str1 != null) {
                map.put(str, str1);
            }
        } else {
            map.put(str, (value == null) ? "" : value.toString());
        }
    }

    private String a(String paramString) {
        if (this.onlCgformFieldMap.containsKey(paramString)) {
            return "$mainTable$" + ((OnlCgformField) this.onlCgformFieldMap.get(paramString)).getDbFieldName();
        }

        return "$subTable$" + paramString;
    }
}
